package be.dch.gui.panels;

import java.awt.Insets;
import java.net.URL;

import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JPanel;

import org.apache.log4j.Logger;

import be.dch.gui.layout.SpacerIcon;

public abstract class AbstractPanel extends JPanel {

    private static final Insets DEFAULT_INSETS = new Insets(5, 5, 5, 5);

    private static final Logger LOG = Logger.getLogger(AbstractPanel.class);

    /** * */
    private static final long serialVersionUID = 3736944631941847612L;

    public abstract String getPanelTitle();

    public abstract Icon getPanelIcon();

    protected Icon createImageIcon(final String path, final String description) {
	return this.createImageIcon(path, description, AbstractPanel.DEFAULT_INSETS);
    }

    protected Icon createImageIcon(final String path, final String description, final Insets insets) {
	Icon result = null;
	final URL imgURL = this.getClass().getResource(path);
	if (imgURL == null) {

	    AbstractPanel.LOG.error("Couldn't find file: " + path);
	} else {
	    final ImageIcon image = new ImageIcon(imgURL, description);
	    result = new SpacerIcon(insets, image);
	}
	return result;
    }

}
